﻿import com.dmotiko.general.*
import mx.transitions.*
import mx.transitions.easing.*

class PhotoClip
extends BaseClip {
	
	private var mcImg:MovieClip;
	private var mcMask:MovieClip;
	private var imgLoader:MovieClipLoader;
	private var mcLoader:LoaderControl;
	private var mcLayout:MovieClip;
	
	private function initClip():Void {
		super.initClip();
		mcMask._alpha = 0;
		mcLayout._alpha = 0;
		imgLoader = new MovieClipLoader();
		imgLoader.addListener(this);
		if (!mcImg) mcImg = this.createEmptyMovieClip("mcImg", this.getNextHighestDepth());
		if(!mcImg.img) mcImg.createEmptyMovieClip("img", 1);
		if ( mcMask ) mcImg.setMask(mcMask);
		if ( mcLoader ) imgLoader.addListener(mcLoader);
	}
	
	public function onLoadProgress(target, loaded, total) {
		dispatchEvent( { target: this, type: BaseClipEvent.CHANGED, loaded: loaded, total: total } );
	}
	
	private function onLoadInit( target:MovieClip ):Void {
		mcImg._alpha = 0;
		registerTween("imgFade", new Tween(mcImg, "_alpha", Regular.easeOut, mcImg._alpha, 100, 1, true));
		layout();
		dispatchEvent( { type: BaseClipEvent.READY, target: this } );
	}
	
	private function layout():Void {
		if ( !mcLayout ) return;
	}
	
	private function refreshData():Void {
		var sPath:String = String(getData());
		imgLoader.loadClip( sPath, mcImg.img);
	}
		
}